import * as fs from 'fs';
import * as path from 'path';
const reg = /\.test\.(ts|js)$/;
function loadTest(dir: string) { 
    let files = fs.readdirSync(dir);
    // console.log(files)
    for (let f of files) { 
        let absolutePath = path.join(dir, f)
        let stat = fs.statSync(absolutePath);
        if (stat.isDirectory()) { 
            loadTest(absolutePath);
            continue;
        }
        
        if (!reg.test(f)) { 
            continue;
        }
        require(absolutePath);
    }
}

import { init } from '../model';
import C from '@jingli/config';
async function main() { 
    await init({
        url: C.postgres.url_test,
        forceSync: true,
    });

    //加载单元测试文件
    loadTest(__dirname);
}

main()
    .then(run)
    .catch((err) => { 
        throw err;
    })
